package jy.controller;

import java.util.List;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import jy.pageModel.Account;
import jy.pageModel.DataGrid;
import jy.pageModel.Json;
import jy.pageModel.PageHelper;
import jy.pageModel.SessionInfo;
import jy.pageModel.User;
import jy.service.AccountServiceI;
import jy.util.ConfigUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

/**
 * 用户控制器
 * 
 * @author 孙宇
 * 
 */
@Controller
@RequestMapping("/accountController")
public class AccountController extends BaseController {

	@Autowired
	private AccountServiceI accountService;



	/**
	 * 跳转到用户账户管理页面
	 * 
	 * @return
	 */
	@RequestMapping("/manager")
	public String manager(Account account,HttpServletRequest request) {
		request.setAttribute("account", account);
		return "/cxgl/account";
	}
	
	
	/**
	 * 跳转到账户操作管理页面
	 * 
	 * @return
	 */	
	
	
	@RequestMapping("/hqmanager")
	public String hqmanager(Account account,HttpServletRequest request) {
		account = accountService.loadAmount(account);
		request.setAttribute("account", account);
		
		return "/cxgl/hq";
	}
	@RequestMapping("/dqmanager")
	public String dqmanager(Account account,HttpServletRequest request) {
		account = accountService.loadAmount(account);
		request.setAttribute("account", account);
		return "/cxgl/dq";
	}
	@RequestMapping("/dhmanager")
	public String dhmanager(Account account,HttpServletRequest request) {
		account = accountService.loadAmount(account);
		request.setAttribute("account", account);
		return "/cxgl/dh";
	}
	
	

	/**
	 * 获取用户数据表格
	 * 
	 * @param user
	 * @return
	 */
	@RequestMapping("/dataGrid")
	@ResponseBody
	public DataGrid dataGrid(Account account, PageHelper ph) {
		return accountService.dataGrid(account, ph);
	}
	
	
	
	@RequestMapping("/recdataGrid")
	@ResponseBody
	public DataGrid recdataGrid(Account account, PageHelper ph) {
		return accountService.recdataGrid(account, ph);
	}
	
	@RequestMapping("/dqdataGrid")
	@ResponseBody
	public DataGrid dqdataGrid(Account account, PageHelper ph) {
		return accountService.dqdataGrid(account, ph);
	}
	
	@RequestMapping("/dhdataGrid")
	@ResponseBody
	public DataGrid dhdataGrid(Account account, PageHelper ph) {
		return accountService.dhdataGrid(account, ph);
	}
	/**
	 * 跳转到添加用户页面
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/addPage")
	public String addhqPage(Account account,HttpServletRequest request) {
		request.setAttribute("account", account);
		return "/cxgl/accountAdd";
	}

	@RequestMapping("/hqdePage")
	public String hqdePage(Account account,HttpServletRequest request) {
		request.setAttribute("account", account);
		return "/cxgl/hqde";
	}
	
	@RequestMapping("/hqdrPage")
	public String hqdrPage(Account account,HttpServletRequest request) {
		account = accountService.loadAmount(account);
		request.setAttribute("account", account);
		return "/cxgl/hqdr";
	}
	@RequestMapping("/hqtrPage")
	public String hqtrPage(Account account,HttpServletRequest request) {
		account = accountService.loadAmount(account);
		request.setAttribute("account", account);
		return "/cxgl/hqtr";
	}
	
	@RequestMapping("/hqde")
	@ResponseBody
	public Json hqde(Account account,HttpServletRequest request) {
		
		Json j = new Json();
		try {
			account = accountService.hqde(account);
			j.setSuccess(true);
			j.setMsg("成功!");
			j.setObj(account);
		} catch (Exception e) {
			// e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}
	
	@RequestMapping("/hqdr")
	@ResponseBody
	public Json hqdr(Account account,HttpServletRequest request) {
		Json j = new Json();
		try {
			account = accountService.hqdr(account);
			j.setSuccess(true);
			j.setMsg(account.getMsg());
			j.setObj(account);
		} catch (Exception e) {
			// e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}
	
	@RequestMapping("/hqtr")
	@ResponseBody
	public Json hqtr(Account account,HttpServletRequest request) {
		Json j = new Json();
		try {
			account = accountService.hqtr(account);
			j.setSuccess(true);
			j.setMsg(account.getMsg());
			j.setObj(account);
		} catch (Exception e) {
			// e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/dqdePage")
	public String dqdePage(Account account,HttpServletRequest request) {
		request.setAttribute("account", account);
		return "/cxgl/dqde";
	}
	
	@RequestMapping("/dqdrPage")
	public String dqdrPage(Account account,HttpServletRequest request) {
		request.setAttribute("account", account);
		return "/cxgl/dqdr";
	}

	
	@RequestMapping("/dqde")
	@ResponseBody
	public Json dqde(Account account,HttpServletRequest request) {
		
		Json j = new Json();
		try {
			account = accountService.dqde(account);
			j.setSuccess(true);
			j.setMsg("成功!");
			j.setObj(account);
		} catch (Exception e) {
			// e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}
	
	@RequestMapping("/dqdr")
	@ResponseBody
	public Json dqdr(Account account,HttpServletRequest request) {
		Json j = new Json();
		try {
			account = accountService.dqdr(account);
			j.setSuccess(true);
			j.setMsg(account.getMsg());
			j.setObj(account);
		} catch (Exception e) {
			// e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}
	
	@RequestMapping("/dhdePage")
	public String dhdePage(Account account,HttpServletRequest request) {
		request.setAttribute("account", account);
		return "/cxgl/dhde";
	}
	
	@RequestMapping("/dhdrPage")
	public String dhdrPage(Account account,HttpServletRequest request) {
		request.setAttribute("account", account);
		return "/cxgl/dhdr";
	}

	
	@RequestMapping("/dhde")
	@ResponseBody
	public Json dhde(Account account,HttpServletRequest request) {
		
		Json j = new Json();
		try {
			account = accountService.dhde(account);
			j.setSuccess(true);
			j.setMsg("成功!");
			j.setObj(account);
		} catch (Exception e) {
			// e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}
	
	@RequestMapping("/dhdr")
	@ResponseBody
	public Json dhdr(Account account,HttpServletRequest request) {
		Json j = new Json();
		try {
			account = accountService.dhdr(account);
			j.setSuccess(true);
			j.setMsg(account.getMsg());
			j.setObj(account);
		} catch (Exception e) {
			// e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	/**
	 * 添加用户
	 * 
	 * @return
	 */
	@RequestMapping("/add")
	@ResponseBody
	public Json add(Account account) {
		Json j = new Json();
		try {
			Integer nid= accountService.add(account);
			j.setSuccess(true);
			j.setMsg("添加成功!账户编号为:"+nid);
			j.setObj(account);
		} catch (Exception e) {
			// e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}


	

	/**
	 * 删除用户
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Json delete(String id, HttpSession session) {
		Json j = new Json();
		accountService.delete(id);
		j.setMsg("删除成功！");
		j.setSuccess(true);
		return j;
	}

	

}
